home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d883.lha / BBBBS / BBBBS59.lha / rexx / bbsUSER.rexx < prev    next >
OS/2 REXX Batch file  |  1993-06-12  |  10KB  |  342 lines

  1. /*   $VER: 5.9 bbsUSER.rexx (11.6.93)
  2.  -  counts upload/download statistics -
  3.  copyright 1990-93 Richard Lee Stockton 
  4.         - FREELY DISTRIBUTABLE -
  5. */
  6.  
  7. HOW_MANY=10
  8. CALL PRAGMA('P',-2)
  9. SIGNAL ON ERROR
  10. SIGNAL ON SYNTAX
  11. SIGNAL ON FAILURE
  12. NUMERIC DIGITS 14
  13.  
  14. CALL TIME('R')
  15. inarg=''
  16. PARSE ARG inarg .
  17. test=COMPRESS(UPPER(inarg),' -')
  18. IF test='?' | test='H' | test='USAGE' | test='HELP' THEN
  19.   DO
  20.     SAY 'Usage: rx bbsUSER [filename or CLI]'
  21.     SAY
  22.     SAY 'CLI writes to the console.'
  23.     SAY 'If a filename or the letters CLI are not included,'
  24.     SAY 'writes to a file called Information/STATS.USER'
  25.   END
  26.  
  27. IF inarg='' THEN
  28.   DO
  29.     CALL CLOSE(STDOUT)
  30.     CALL OPEN(STDOUT,'RAM:bbsUSER.STDOUT','W')
  31.   END
  32.  
  33. figarg='s:CONFIG.BBS'
  34. IF ~EXISTS(figarg) THEN figarg='BBS:BBS_TEXT/CONFIG.BBS'
  35. x=OPEN(f,figarg,'R')
  36. IF x=0 THEN
  37.   DO
  38.     SAY 's:CONFIG.BBS and BBS:BBS/CONFIG.BBS are both missing!'
  39.     EXIT(20)
  40.   END
  41.  
  42. CALL SETCLIP('BBS_STAT','ON')
  43. lynes.=''
  44. DO i=1 TO 6
  45.   lynes.i=READLN(f)
  46. END
  47. CALL CLOSE(f)
  48.  
  49. compos=POS('/*',lynes.1)
  50. IF compos>0 THEN lynes.1=LEFT(lynes.1,compos-1)
  51.  
  52. bbsname = STRIP(lynes.1)
  53. sysop   = WORD(lynes.2,1)
  54. bbspath = WORD(lynes.6,1)
  55. IF ~EXISTS(bbspath) THEN
  56.   DO
  57.     SAY bbspath 'does not exist!'
  58.     CALL SETCLIP('BBS_STAT')
  59.     EXIT(20)
  60.   END
  61. testchar=RIGHT(bbspath,1)
  62. IF testchar~='/' & testchar~=':' THEN bbspath=bbspath'/'
  63.  
  64. counts.=0
  65. DO j=1 TO HOW_MANY
  66.   counts.LOW.j=999999999
  67. END
  68. counts.AGE_YOUNGEST=99999999
  69. ten=0
  70. thirty=0
  71. ninty=0
  72. sixmo=0
  73. ndate=DATE('I')
  74. userlist=SHOWDIR(bbspath'Users','F')
  75. x=FIND(userlist,sysop)
  76. IF x>0 THEN userlist=DELWORD(userlist,x,1)
  77. DO i=1 TO WORDS(userlist)
  78.   thisuser=WORD(userlist,i)
  79.   x=OPEN(f,bbspath'Users/'thisuser,'R')
  80.   IF x=0 THEN
  81.     DO
  82.       SAY thisuser 'userfile would not open!'
  83.       ITERATE i
  84.     END
  85.   lynes.=''
  86.   DO j=1 TO 23
  87.     line=READLN(f)
  88.     IF EOF(f) THEN LEAVE j
  89.     lynes.j=line
  90.   END
  91.   CALL CLOSE(f)
  92.   callcount=WORD(lynes.19,6)
  93.   counts.CALLS=counts.CALLS+callcount
  94.   DO j=HOW_MANY TO 1 BY -1 WHILE callcount>counts.CALLS.j
  95.     jj=j+1
  96.     counts.CALLS.jj=counts.CALLS.j
  97.     counts.ID.CALLS.jj=counts.ID.CALLS.j
  98.     counts.CALLS.j=callcount
  99.     counts.ID.CALLS.j=thisuser
  100.   END
  101.   ontime=WORD(lynes.19,1)*60+WORD(lynes.19,3)
  102.   counts.MINUTES=counts.MINUTES+ontime
  103.   DO j=HOW_MANY TO 1 BY -1 WHILE ontime>counts.ON_MINS.j
  104.     jj=j+1
  105.     counts.ON_MINS.jj=counts.ON_MINS.j
  106.     counts.ID.ON_MINS.jj=counts.ID.ON_MINS.j
  107.     counts.ON_MINS.j=ontime
  108.     counts.ID.ON_MINS.j=thisuser
  109.   END
  110.   IF WORDS(lynes.12)>3 & DATATYPE(WORD(lynes.12,4),'N') THEN
  111.     DO
  112.       counts.AGE_INDEX=counts.AGE_INDEX+1
  113.       age=0
  114.       IF UPPER(WORD(lynes.12,3))='AGE:' THEN
  115.         DO
  116.           age=WORD(lynes.12,4)
  117.           counts.AGE_TOTAL=counts.AGE_TOTAL+age
  118.         END
  119.       ELSE IF UPPER(WORD(lynes.12,3))='BIRTHDAY:' THEN
  120.         DO
  121.           age=LEFT(DATE('S'),4)-LEFT(WORD(lynes.12,4),4)
  122.           counts.AGE_TOTAL=counts.AGE_TOTAL+age
  123.           IF SUBSTR(DATE('S'),5,2)<SUBSTR(WORD(lynes.12,4),5,2) THEN
  124.             DO
  125.               counts.AGE_TOTAL=counts.AGE_TOTAL-1
  126.               age=age-1
  127.             END
  128.         END
  129.       IF age>0 & age<counts.AGE_YOUNGEST THEN counts.AGE_YOUNGEST=age
  130.       IF age>counts.AGE_OLDEST THEN counts.AGE_OLDEST=age
  131.     END
  132.   idate=DATE('I',STRIP(WORD(lynes.13,1)),'S')
  133.   days=ndate-idate
  134.   IF days<11 THEN ten=ten+1
  135.   IF days<31 THEN thirty=thirty+1
  136.   IF days<91 THEN ninty=ninty+1
  137.   IF days<183 THEN sixmo=sixmo+1
  138.   upfiles=0
  139.   upbytes=1
  140.   dnfiles=0
  141.   dnbytes=1
  142.   IF WORDS(lynes.14)>3 THEN
  143.     DO
  144.       upfiles=WORD(lynes.14,1)
  145.       upbytes=WORD(lynes.14,3)
  146.     END
  147.   IF WORDS(lynes.15)>3 THEN
  148.     DO
  149.       dnfiles=WORD(lynes.15,1)
  150.       dnbytes=WORD(lynes.15,3)
  151.     END
  152.   IF upbytes<1 THEN upbytes=1
  153.   counts.UP_FILES=counts.UP_FILES+upfiles
  154.   counts.UP_BYTES=counts.UP_BYTES+upbytes
  155.   counts.DN_FILES=counts.DN_FILES+dnfiles
  156.   counts.DN_BYTES=counts.DN_BYTES+dnbytes
  157.   DO j=HOW_MANY TO 1 BY -1 WHILE upfiles>counts.HIGH.UP_FILES.j
  158.     jj=j+1
  159.     counts.HIGH.UP_FILES.jj=counts.HIGH.UP_FILES.j
  160.     counts.ID.UP_FILES.jj=counts.ID.UP_FILES.j
  161.     counts.HIGH.UP_FILES.j=upfiles
  162.     counts.ID.UP_FILES.j=thisuser
  163.   END
  164.   DO j=HOW_MANY TO 1 BY -1 WHILE upbytes>counts.HIGH.UP_BYTES.j
  165.     jj=j+1
  166.     counts.HIGH.UP_BYTES.jj=counts.HIGH.UP_BYTES.j
  167.     counts.ID.UP_BYTES.jj=counts.ID.UP_BYTES.j
  168.     counts.HIGH.UP_BYTES.j=upbytes
  169.     counts.ID.UP_BYTES.j=thisuser
  170.   END
  171.   DO j=HOW_MANY TO 1 BY -1 WHILE dnfiles>counts.HIGH.DN_FILES.j
  172.     jj=j+1
  173.     counts.HIGH.DN_FILES.jj=counts.HIGH.DN_FILES.j
  174.     counts.ID.DN_FILES.jj=counts.ID.DN_FILES.j
  175.     counts.HIGH.DN_FILES.j=dnfiles
  176.     counts.ID.DN_FILES.j=thisuser
  177.   END
  178.   DO j=HOW_MANY TO 1 BY -1 WHILE dnbytes>counts.HIGH.DN_BYTES.j
  179.     jj=j+1
  180.     counts.HIGH.DN_BYTES.jj=counts.HIGH.DN_BYTES.j
  181.     counts.ID.DN_BYTES.jj=counts.ID.DN_BYTES.j
  182.     counts.HIGH.DN_BYTES.j=dnbytes
  183.     counts.ID.DN_BYTES.j=thisuser
  184.   END
  185.   IF (dnbytes=1)&(upbytes=1) THEN NOP
  186.   ELSE
  187.     DO j=HOW_MANY TO 1 BY -1 WHILE (dnbytes/upbytes)<counts.LOW.j
  188.       jj=j+1
  189.       counts.LOW.jj=counts.LOW.j
  190.       counts.ID.LOW.jj=counts.ID.LOW.j
  191.       counts.LOW.j=dnbytes/upbytes
  192.       counts.ID.LOW.j=thisuser
  193.     END
  194.   DO j=HOW_MANY TO 1 BY -1 WHILE (dnbytes/upbytes)>counts.HIGH.j
  195.     jj=j+1
  196.     counts.HIGH.jj=counts.HIGH.j
  197.     counts.ID.HIGH.jj=counts.ID.HIGH.j
  198.     counts.HIGH.j=dnbytes/upbytes
  199.     counts.ID.HIGH.j=thisuser
  200.   END
  201.   totwrit=0
  202.   DO j=1 TO 99
  203.     thisnum=WORD(lynes.23,j)
  204.     IF DATATYPE(thisnum,'N') THEN totwrit=totwrit+thisnum
  205.   END
  206.   DO j=HOW_MANY TO 1 BY -1 WHILE totwrit>counts.HIGH.MSGS.j
  207.     jj=j+1
  208.     counts.HIGH.MSGS.jj=counts.HIGH.MSGS.j
  209.     counts.ID.MSGS.jj=counts.ID.MSGS.j
  210.     counts.HIGH.MSGS.j=totwrit
  211.     counts.ID.MSGS.j=thisuser
  212.   END
  213. END
  214.  
  215.  
  216. /* OUTPUT */
  217.  
  218. IF inarg='' THEN inarg=bbspath'Information/STATS.USER'
  219. IF UPPER(inarg)~='CLI' THEN
  220.   DO
  221.     CALL CLOSE(STDOUT)
  222.     CALL OPEN(STDOUT,inarg,'W')
  223.     IF x=0 THEN
  224.       DO
  225.         SAY inarg 'would not open for writing!'
  226.         CALL SETCLIP('BBS_STAT')
  227.         EXIT(20)
  228.       END
  229.   END
  230.  
  231. SAY LEFT('-',75,'-')
  232. SAY CENTER(bbsname 'USER statistics through' DATE() 'at' TIME('C'),75)
  233. SAY LEFT('-',75,'-')
  234. SAY CENTER('Does not include sysop.',75)
  235. SAY LEFT('-',75,'-')
  236. SAY
  237. IF counts.AGE_INDEX>0 THEN
  238.   SAY CENTER('Of' WORDS(userlist) 'total users,' counts.AGE_INDEX 'gave their ages.',75)
  239.   SAY CENTER('The youngest is' counts.AGE_YOUNGEST'    The oldest is' counts.AGE_OLDEST'    The average is' TRUNC(counts.AGE_TOTAL/counts.AGE_INDEX+.005,2),75)
  240. SAY
  241. SAY RIGHT(comma(counts.UP_BYTES),15) 'bytes in' RIGHT(comma(counts.UP_FILES),7) 'files have been uploaded by these users.'
  242. SAY RIGHT(comma(counts.DN_BYTES),15) 'bytes in' RIGHT(comma(counts.DN_FILES),7) 'files have been downloaded by these users.'
  243. SAY
  244. SAY
  245. SAY 'Most public  messages:' RIGHT(comma(counts.HIGH.MSGS.1),14) counts.ID.MSGS.1
  246. DO j=2 TO HOW_MANY
  247.   IF counts.HIGH.MSGS.j>0 THEN
  248.     SAY RIGHT(comma(counts.HIGH.MSGS.j),37) counts.ID.MSGS.j
  249. END
  250. SAY
  251. SAY 'Most files   uploaded:' RIGHT(comma(counts.HIGH.UP_FILES.1),14) counts.ID.UP_FILES.1
  252. DO j=2 TO HOW_MANY
  253.   IF counts.HIGH.UP_FILES.j>0 THEN
  254.     SAY RIGHT(comma(counts.HIGH.UP_FILES.j),37) counts.ID.UP_FILES.j
  255. END
  256. SAY
  257. SAY 'Most bytes   uploaded:' RIGHT(comma(counts.HIGH.UP_BYTES.1),14) counts.ID.UP_BYTES.1
  258. DO j=2 TO HOW_MANY
  259.   IF counts.HIGH.UP_BYTES.j>0 THEN
  260.     SAY RIGHT(comma(counts.HIGH.UP_BYTES.j),37) counts.ID.UP_BYTES.j
  261. END
  262. SAY
  263. SAY 'Most files downloaded:' RIGHT(comma(counts.HIGH.DN_FILES.1),14) counts.ID.DN_FILES.1
  264. DO j=2 TO HOW_MANY
  265.   IF counts.HIGH.DN_FILES.j>0 THEN
  266.     SAY RIGHT(comma(counts.HIGH.DN_FILES.j),37) counts.ID.DN_FILES.j
  267. END
  268. SAY
  269. SAY 'Most bytes downloaded:' RIGHT(comma(counts.HIGH.DN_BYTES.1),14) counts.ID.DN_BYTES.1
  270. DO j=2 TO HOW_MANY
  271.   IF counts.HIGH.DN_BYTES.j>0 THEN
  272.     SAY RIGHT(comma(counts.HIGH.DN_BYTES.j),37) counts.ID.DN_BYTES.j
  273. END
  274. SAY
  275. SAY
  276. SAY 'Best  (lowest)  ratio, downloads divided by uploads:'
  277. DO j=1 TO HOW_MANY
  278.   IF counts.LOW.j<999999999 THEN
  279.     SAY RIGHT(comma(counts.LOW.j%1)||RIGHT(TRUNC(counts.LOW.j+.000005,5),6),37) counts.ID.LOW.j
  280. END
  281. SAY
  282. SAY 'Worst (highest) ratio, downloads divided by uploads:'
  283. DO j=1 TO HOW_MANY
  284.   IF counts.HIGH.j>0 THEN
  285.     SAY RIGHT(comma(counts.HIGH.j%1),37) counts.ID.HIGH.j
  286. END
  287. SAY
  288. SAY 'Most Minutes Spent On' bbsname':'
  289. DO j=1 TO HOW_MANY
  290.   IF counts.ON_MINS.j>0 THEN
  291.     SAY RIGHT(comma(counts.ON_MINS.j%1),37) counts.ID.ON_MINS.j
  292. END
  293. SAY
  294. SAY 'Most Calls To' bbsname':'
  295. DO j=1 TO HOW_MANY
  296.   IF counts.CALLS.j>0 THEN
  297.     SAY RIGHT(comma(counts.CALLS.j%1),37) counts.ID.CALLS.j
  298. END
  299. SAY
  300. SAY 'Average Usage In Minutes Per Call:' TRUNC(.05+counts.MINUTES/counts.CALLS,1)
  301. SAY
  302. users=WORDS(userlist)
  303. SAY RIGHT(comma(users),7) 'users.'
  304. SAY RIGHT(comma(sixmo),7)',' RIGHT(((sixmo*100)/users)%1,2)'%, have called in the last 6 months.'
  305. SAY RIGHT(comma(ninty),7)',' RIGHT(((ninty*100)/users)%1,2)'%, have called in the last 90 days.'
  306. SAY RIGHT(comma(thirty),7)',' RIGHT(((thirty*100)/users)%1,2)'%, have called in the last 30 days.'
  307. SAY RIGHT(comma(ten),7)',' RIGHT(((ten*100)/users)%1,2)'%, have called in the last 10 days.'
  308. SAY
  309. SAY ' - total seconds to compile this user report:' TIME('E')' -'
  310. SAY
  311. CALL SETCLIP('BBS_STAT')
  312. EXIT;
  313.  
  314.  
  315. comma:
  316. ARG num .
  317. dgt=LENGTH(num)
  318. numtext=''
  319. IF dgt>3 THEN numtext=','RIGHT(num,3)
  320. IF dgt>6 THEN numtext=','LEFT(RIGHT(num,6),3)||numtext
  321. IF dgt>9 THEN
  322.   DO
  323.     numtext=','LEFT(RIGHT(num,9),3)||numtext
  324.     numtext=LEFT(num,dgt-9)||numtext
  325.   END
  326. ELSE IF dgt>6 THEN numtext=LEFT(num,dgt-6)||numtext
  327. ELSE IF dgt>3 THEN numtext=LEFT(num,dgt-3)||numtext
  328. ELSE numtext=num
  329. RETURN(numtext)
  330.  
  331.  
  332. SYNTAX:
  333. FAILURE:
  334. ERROR:
  335. SAY 'Line:' SIGL ERRORTEXT(RC)
  336. SAY thisuser
  337. SAY
  338. CALL SETCLIP('BBS_STAT')
  339. EXIT;
  340.  
  341. /* end of bbsUSER.rexx */
  342.